<?php


namespace App\Admin\Actions\Tools;


use App\Admin\Actions\BatchAction;
use App\Models\AdminUser;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class TransverseComplete extends BatchAction
{
    protected $selector = '.transverse-complete-posts';

    public function handle(Collection $collection, Request $request)
    {
        $state = $request->get('state', 0);
        foreach ($collection as $model) {
            $model->state = $state;
            $model->save();
        }
        return $this->response()->success('操作成功！')->refresh();
    }


    public function form()
    {
        $this->radio('state', '研究状态')->options(['在研', '已结项'])->default(1);
    }

    public function html()
    {
        return "<a class='transverse-complete-posts btn btn-sm btn-primary'>批量研究状态</a>";
    }

    public function authorize(AdminUser $user, Collection $collection)
    {
        return $user->role_type == 1;
    }

}
